using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Input;
using  UCOLOR.Helpers;
//using  UCOLOR.Model;


namespace  UCOLOR.ViewModel {
    public class MainData : ModuleData {
        public override void Load() {
            base.Load();
           // ListingTileData = new ListingTileData();
           // ListingTileData.Home = DataSource.Current.GetHomes()[0];
           // ListingTileData.Image = ListingTileData.Home.Photo;
           // AgentsTileData = DataSource.Current.GetAgents()[0];
        }
    }
    public class Main : Module {
        int listingTileHomeIndex = 0;
        int listingTilePhotoIndex = 1;
        int agentsTileContentIndex = 0;
        Type currentModuleDataType;
        Module currentModule;

        public Main() {
            IsPersistentModule = true;
            ShowModule<MainData>(null);
        }
        public override void InitData(object parameter) {
            base.InitData(parameter);
        }
        public MainData MainData { get { return (MainData)Data; } }
        public void ShowModule<T>(object parameter) where T : ModuleData, new() {
            CurrentModuleDataType = typeof(T);
            if(typeof(T) == typeof(MainData)) {
                CurrentModule = this;
            } else {
                T data = new T();
                CurrentModule = ModulesManager.CreateModule(null, data, this, parameter);
            }
        }
 
        public Type CurrentModuleDataType {
            get { return currentModuleDataType; }
            set { SetValue<Type>("CurrentModuleDataType", ref currentModuleDataType, value); }
        }
        public Module CurrentModule {
            get { return currentModule; }
            private set { SetValue<Module>("CurrentModule", ref currentModule, value); }
        }
        public Func<object, string> StoryboardSelector { get { return SelectStoryboard; } }
        string SelectStoryboard(object newModuleView) { return newModuleView == View ? "FromLeft" : "FromRight"; }
     
        void CorrectListingTileHomeIndex(int homesCount) {
            listingTileHomeIndex %= homesCount;
        }
        bool CorrectListingTilePhotoIndex(int homesCount, int photosCount) {
            if(listingTilePhotoIndex >= photosCount + 1) {
                listingTilePhotoIndex = 0;
                ++listingTileHomeIndex;
                CorrectListingTileHomeIndex(homesCount);
                return true;
            }
            return false;
        }
        void CorrectAgentsTileContentIndex(int agentsCount) {
            agentsTileContentIndex %= agentsCount;
        }
        #region Commands
        protected override void InitializeCommands() {
            base.InitializeCommands();
            ShowMainCommand = new ExtendedActionCommand(DoShowModule<MainData>, this, "CurrentModuleDataType", AllowSwitchToTheModule, typeof(MainData));
            //ShowListingCommand = new ExtendedActionCommand(DoShowModule<ListingData>, this, "CurrentModuleDataType", AllowSwitchToTheModule, typeof(ListingData));
            //ShowAgentsCommand = new ExtendedActionCommand(DoShowModule<AgentsData>, this, "CurrentModuleDataType", AllowSwitchToTheModule, typeof(AgentsData));
        //    ShowZillowCommand = new SimpleActionCommand(DoShowZillow);
        //    ShowBanksCommand = new ExtendedActionCommand(DoShowModule<BanksData>, this, "CurrentModuleDataType", AllowSwitchToTheModule, typeof(BanksData));
        //    ShowResearchCommand = new SimpleActionCommand(DoShowModule<DraftData>);
        //    ShowUserManagementCommand = new SimpleActionCommand(DoShowModule<DraftData>);
        //    ShowSystemInfoCommand = new SimpleActionCommand(DoShowModule<DraftData>);
        //    ShowStatisticsCommand = new ExtendedActionCommand(DoShowModule<StatisticsData>, this, "CurrentModuleDataType", AllowSwitchToTheModule, typeof(StatisticsData));
        //    ShowLoanCalculatorCommand = new ExtendedActionCommand(DoShowModule<LoanCalculatorData>, this, "CurrentModuleDataType", AllowSwitchToTheModule, typeof(LoanCalculatorData));
        //
        }
        public ICommand ShowMainCommand { get; private set; }
        public ICommand ShowListingCommand { get; private set; }
        public ICommand ShowAgentsCommand { get; private set; }
        public ICommand ShowZillowCommand { get; private set; }
        //void DoShowZillow(object p) { ShowModule<ZillowData>(p); }
        public ICommand ShowBanksCommand { get; private set; }
        public ICommand ShowResearchCommand { get; private set; }
        public ICommand ShowUserManagementCommand { get; private set; }
        public ICommand ShowSystemInfoCommand { get; private set; }
        public ICommand ShowStatisticsCommand { get; private set; }
        public ICommand ShowLoanCalculatorCommand { get; private set; }
        bool AllowSwitchToTheModule(object moduleDataType) {
            return CurrentModuleDataType != moduleDataType as Type;
        }
        void DoShowModule<T>(object p) where T : ModuleData, new() { ShowModule<T>(p); }
        #endregion
    }
}
